import ForceUtil from "solar/util/ForceUtil";

export default class MapBaseInitState {

    static config: {
        player_see: boolean;//全图视野
        initial_lens_height: number;//初始化高度
        gold: number//初始金币
        goldForMapLvl: number//地图等级的平方奖励金币
        wood: number//初始木材
        population: number//人口
        start_text: string//初始文本
        start_CreateUnitType: string//初始创建单位类型
        open_gives_bounty: number[]//获得奖励

    } = {
        player_see: true,//全图视野
        initial_lens_height: 2500,//初始化高度
        gold: 0,//初始金币
        goldForMapLvl: 0,//地图等级的平方奖励金币
        wood: 0,//初始木材
        population: 100,//人口
        start_text: "",//初始文本
        start_CreateUnitType: "",//初始创建单位类型
        open_gives_bounty: [],//

    }

    constructor() {
        let cfg = MapBaseInitState.config
        ForceUtil.forUserForce(player => {
            if (MapBaseInitState.config.goldForMapLvl > 0) {
                let mapLvl = DzAPI_Map_GetMapLevel(player)
                let mapLveAdd = mapLvl * mapLvl * MapBaseInitState.config.goldForMapLvl;
                DisplayTimedTextToPlayer(player, 0, 0, 10, '|cff00ffff你获得了' + mapLveAdd + '(地图等级^2*' + MapBaseInitState.config.goldForMapLvl + ")的地图等级奖励金币！");
                SetPlayerState(player, PLAYER_STATE_RESOURCE_GOLD, mapLveAdd + MapBaseInitState.config.gold);
            } else {
                SetPlayerState(player, PLAYER_STATE_RESOURCE_GOLD, MapBaseInitState.config.gold);
            }

            SetPlayerState(player, PLAYER_STATE_RESOURCE_LUMBER, MapBaseInitState.config.wood);
            SetPlayerState(player, PLAYER_STATE_RESOURCE_FOOD_CAP, MapBaseInitState.config.population);
            SetCameraFieldForPlayer(player, CAMERA_FIELD_TARGET_DISTANCE, MapBaseInitState.config.initial_lens_height, 0);

            if (cfg.start_text && cfg.start_text.length > 0) {
                DisplayTimedTextFromPlayer(player, 0, 0, 10, MapBaseInitState.config.start_text)
            }
            if (cfg.start_CreateUnitType && cfg.start_CreateUnitType.length > 3) {
                let loc = GetPlayerStartLocationLoc(player)
                CreateUnit(player, FourCC(cfg.start_CreateUnitType), GetLocationX(loc), GetLocationY(loc), 0);
            }
        });

        if (MapBaseInitState.config.player_see) {
            FogEnableOff();
            FogMaskEnableOff();
        }
        for (const playerindex of MapBaseInitState.config.open_gives_bounty) {
            SetPlayerState(Player(playerindex - 1), PLAYER_STATE_GIVES_BOUNTY, 1)
        }
    }


}
